//
//  ReleaseCaseViewController.m
//  yonghu
//
//  Created by 浪尖渝力 on 2018/1/15.
//  Copyright © 2018年 com.DJS. All rights reserved.
//

#import "ReleaseCaseViewController.h"
#import "ReleaseCaseView.h"
#import "GXXZViewController.h"
#import "CaseProgressViewController.h"


@interface ReleaseCaseViewController ()
@property(nonatomic,strong)ReleaseCaseView *aView;
@property(nonatomic,strong)NSString *gengXin;
@end

@implementation ReleaseCaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    NSNotificationCenter * center = [NSNotificationCenter defaultCenter];
    //添加当前类对象为一个观察者，name和object设置为nil，表示接收一切通知
    [center addObserver:self selector:@selector(networkDidReceiveMessage:) name:@"login" object:nil];
    _gengXin=@"0";
    
    self.navigationItem.title=@"案件详情";
    _aView=[ReleaseCaseView new];
    [self.view addSubview:_aView];
    [_aView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_equalTo(0);
    }];
    _aView.customSelectedBlock = ^ (int abc)
    {
        if (abc==2) {
            [self.navigationController popViewControllerAnimated:YES];
        }
        else{
            [ZQTools cleanViewSubviews:_aView];
            [self loadData];
        }
        
    };
    
    _aView.viewController=self;
    [self loadData];
    
    if (_isOrNo) {
        
        self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc] initWithTitle:@"更新" style:UIBarButtonItemStylePlain target:self action:@selector(pushToGX:)];
        
        UIButton *btn=[UIButton new];
        [self.view addSubview:btn];
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.mas_equalTo(0);
            make.height.mas_equalTo(50);
        }];
        btn.backgroundColor=_backgroundColor;
        [btn setTitle:@"案件进度" forState:0];
        [btn setTitleColor:[UIColor whiteColor] forState:0];
        [btn addTarget:self action:@selector(pushToJinDu:) forControlEvents:UIControlEventTouchUpInside];
    }
    
}
-(void)networkDidReceiveMessage:(NSNotification *)notification{
    _gengXin=@"1";
    
}
-(void)viewWillAppear:(BOOL)animated{
    if ([_gengXin isEqualToString:@"1"]) {
        _gengXin=@"0";
        [self pushToJinDu:nil];
    }
}

-(IBAction)pushToJinDu:(id)sender{
    CaseProgressViewController *caseView=[[CaseProgressViewController alloc] init];
    caseView.litigation_id=[_dic objectForKey:@"litigation_id"];
    [ZQTools pushNextViewController:self andRootController:caseView];
    
}
-(IBAction)pushToGX:(id)sender{
    NSNumber *litigation_id1=[_dic objectForKey:@"litigation_id"];
    NSString *litigation_id=[NSString stringWithFormat:@"%@",litigation_id1];
    GXXZViewController *gX=[[GXXZViewController alloc] init];
    gX.litigation_id=litigation_id;
    [ZQTools pushNextViewController:self andRootController:gX];
}
-(void)loadData{
    
    NSDictionary *userDic = [NSKeyedUnarchiver unarchiveObjectWithFile:_userModelFile];
    NSString *token=[userDic objectForKey:@"token"];
    NSNumber *litigation_id1=[_dic objectForKey:@"litigation_id"];
    NSString *litigation_id=[NSString stringWithFormat:@"%@",litigation_id1];
    NSNumber *waiter_id1=[userDic objectForKey:@"waiter_role"];
    NSString *user_id=[NSString stringWithFormat:@"%@",waiter_id1];
    
    NSNumber *waiter_id2=[userDic objectForKey:@"waiter_id"];
    NSString *waiter_id=[NSString stringWithFormat:@"%@",waiter_id2];
    
    NSDictionary *dic=[NSDictionary dictionaryWithObjectsAndKeys:litigation_id,@"litigation_id",waiter_id,@"waiter_id",user_id,@"waiter_role",token,@"token",@"1",@"user_role", nil];
    [ZQTools AFNPostDataUrl:@"waiter/Litigation/litigation_info" Dict:dic andTableView:nil andViewController:self andSuccessBlock:^(id responseObject) {
        
        _aView.dic=responseObject;
        [_aView creatView];
        
    } anderrorBlock:nil];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
